package com.agency8x.controller;

import java.util.List;

import com.agency8x.interceptor.CheckLoginInterceptor;
import com.jfinal.aop.Before;
import com.jfinal.config.Constants;
import com.jfinal.core.Controller;
import com.jfinal.upload.UploadFile;

/**
 * 文件上传控制器
 * 
 * @author SoChishun
 * @version 1.0 2017-5-22
 */
@Before(CheckLoginInterceptor.class)
public class UploaderController extends Controller {

	public void single_file() {
		this.setAttr("debug", this.getPara("debug", "N"));
		this.setAttr("callback", this.getPara("callback", "single_uploader_cb"));
		this.setAttr("name", this.getPara("name", ""));
		render("single_file.html");
	}

	public void kindeditor_upload() {
		String uploadPath = "/face/";
		List<UploadFile> uploadFiles = this.getFiles(uploadPath);
		String filename = null;
		for (UploadFile upFile : uploadFiles) {
			filename = upFile.getFileName();
		}

		if (null == filename) {
			this.renderJson("{\"error\":1,\"message\":\"文件上传失败!\"}");
		} else {
			this.renderJson("{\"error\":0,\"url\":\"/uploads" +uploadPath + filename + "\"}");
		}
	}
}
